package day2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public
class TestCopy2 {
    public static
    void main(String[] args) {
        //try catch
        //可以将需要关闭的资源放在try的括号中，会自动关闭
        try(FileInputStream fis =new FileInputStream("D:\\IO\\movie\\1.mp4");
            FileOutputStream fos =new FileOutputStream("D:\\IO\\movie\\11.mp4"))
        {

            File f=new File("D:\\IO\\movie\\1.mp4");
            int len;
            long size=f.length();
            long i=0;
            byte[] bs=new byte[1024];
            //获取开始时间
            long start=System.currentTimeMillis();
            while((len=fis.read(bs))!=-1){
                i+=len;
                fos.write(bs,0,len);
                System.out.printf("当前进度：%.5f%%\n",(i*100.0/size));
            }
            //获取结束时间
            long end=System.currentTimeMillis();
            System.out.println("复制完成，耗时："+(end-start)+"ms");

        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
